import 'package:flutter/material.dart';
import 'package:xindong/utils/xindong_image_util.dart';

// 按钮类型
enum XinDongHorizontalButtonType {
  exit, // 退出
  minimize, // 最小化
  microphone_off, // 麦克风已关闭
  microphone_on, // 麦克风已开启
  voice_off, // 扬声器已关闭
  voice_on, // 扬声器已开启
  setting, // 设置
  share, // 分享
  gift, // 礼物
  userSpace, // 空间
  favorite, // 喜欢
  reverse_lens, // 切换摄像头
  camera_off, // 摄像头已关闭
  camera_on, //摄像头已开启
  beauty, //美颜
}

// 按钮模型
class XinDongHorizontaButtonClass {
  late XinDongHorizontalButtonType type; // 类型
  String? iconName; // 图片名称
  String? name; // 名称
  // 构造函数
  XinDongHorizontaButtonClass({required this.type, this.iconName, this.name});
}

// 房间按钮列表
//
// size 按钮大小
// buttonNameList 按钮本地图片名称
// onTap 点击按钮回调
class XinDongHorizontalButtons extends StatelessWidget {
  final double size;
  final double space;

  final List<XinDongHorizontaButtonClass>? dataList;
  final ValueChanged<XinDongHorizontalButtonType> onTap;
  final ValueChanged<XinDongHorizontalButtonType>? onLongPress;

  const XinDongHorizontalButtons({
    Key? key,
    this.size = 38.0,
    this.space = 10.0,
    this.dataList,
    required this.onTap,
    this.onLongPress,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      height: size,
      child: ListView.separated(
        shrinkWrap: true,
        scrollDirection: Axis.horizontal,
        itemCount: dataList?.length ?? 0,
        itemBuilder: (BuildContext context, int index) {
          XinDongHorizontaButtonClass model = dataList![index];
          return SizedBox(
            width: size,
            height: size,
            child: GestureDetector(
              onTap: () => onTap(model.type),
              onLongPress: () => onLongPress == null ? null : onLongPress!(model.type),
              child: ImageUtil.asset(model.iconName!),
            ),
          );
        },
        separatorBuilder: (BuildContext context, int index) {
          return SizedBox(width: space);
        },
      ),
    );
  }
}
